Imports System
Imports System.Configuration
Imports System.Data
Imports System.Data.SqlClient
Imports System.Text
Imports System.Web
Imports System.Xml
Imports Subsonic
Imports ClubStarterKit.Data

Partial Class ForumRss
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Response.Clear()
        Response.ContentType = "text/xml"
        Dim objX As New XmlTextWriter(Response.OutputStream, Encoding.UTF8)
        objX.WriteStartDocument()
        objX.WriteStartElement("rss")
        objX.WriteAttributeString("version", "2.0")
        objX.WriteStartElement("channel")
        objX.WriteElementString("title", ClubStarterKit.Web.Settings.Name() & ": Forum Posts")
        objX.WriteElementString("link", ClubStarterKit.Web.Settings.SiteURL() & "Forum/Topics.aspx")
        objX.WriteElementString("description", "Forum Posts for " & ClubStarterKit.Web.Settings.Name())
        objX.WriteElementString("copyright", ClubStarterKit.Web.Settings.Copyright())
        objX.WriteElementString("ttl", "20")
        Dim qry As New Query(Tables.Messages)
        qry.QueryType = QueryType.Select
        qry.OrderBy = OrderBy.Desc(Messages.Columns.Postdate)
        qry.SelectList = Messages.Columns.Subject & "," & Messages.Columns.Threadid & "," & Messages.Columns.Body & "," & Messages.Columns.Memberid
        Dim objReader As SqlDataReader = qry.ExecuteReader()
        While objReader.Read()
            objX.WriteStartElement("item")
            objX.WriteElementString("title", objReader.GetString(0))
            objX.WriteElementString("description", objReader.GetString(2))
            objX.WriteElementString("link", ClubStarterKit.Web.Settings.SiteURL() & "Forum/Thread.aspx?th=" & objReader.GetInt32(1))
            objX.WriteElementString("author", ClubStarterKit.Web.Members.FirstAndLastName(objReader.GetGuid(3)))
            objX.WriteEndElement()
        End While
        objReader.Close()
        objX.WriteEndElement()
        objX.WriteEndElement()
        objX.WriteEndDocument()
        objX.Flush()
        objX.Close()
        Response.End()
    End Sub
End Class
